package com.tiany.kotlin_study

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_second.*

class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)
        //跳转到页面3
        sec_btn1.setOnClickListener {
            val data="happy birthday!"
            val intent = Intent(this,ThirdActivity::class.java)
            //intent.putExtra("extr_data1",data)
            startActivityForResult(intent,1)
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        when(requestCode){
            1 -> if(requestCode== RESULT_OK){
                val returnData=data?.getStringExtra("data_return")
                Toast.makeText(this,returnData,Toast.LENGTH_SHORT).show()
            }
        }

    }
}